
var localhost = '172.16.5.236'
$.get('http://'+localhost+':8000/web/taxiidQuery/', function (_rawData) {
	var idlist=_rawData['idlist'];
	var optgroup;
	var option;
	for (i = 0; i < idlist.length; i++) {
		optgroup = document.getElementById("optgroup2");
　　	option = document.createElement("option");
　　	option.innerHTML = idlist[i];//添加内容
　　	optgroup.appendChild(option);
	 }
});

var colorhash=['#7fffff','#7fffbf','#7fff7f','#ffff7f','#ffbf7f','#ff7f7f']

var styleFunction = function(feature) {
	  var pitch = feature['values_']['speed'];
	  var style = null;
	  if (pitch<=10) {
		  style = new ol.style.Style({
				image: new ol.style.Circle({
					radius: 5,//半径
					fill: new ol.style.Fill({//填充样式
					color: colorhash[0],
				}),
				stroke: new ol.style.Stroke({//边界样式
					color: '#DCDCDC',
					width: 1
				})
				})
		  });
	  }else if(pitch>10 && pitch<=20){
		  style = new ol.style.Style({
			image: new ol.style.Circle({
				radius: 5,//半径
				fill: new ol.style.Fill({//填充样式
					color: colorhash[1],
				}),
				stroke: new ol.style.Stroke({//边界样式
					color: '#DCDCDC',
					width: 1
				})
			})
		  });
	  }else if(pitch>20 && pitch<=30){
		  style = new ol.style.Style({
			image: new ol.style.Circle({
				radius: 5,//半径
				fill: new ol.style.Fill({//填充样式
					color: colorhash[2],
				}),
				stroke: new ol.style.Stroke({//边界样式
					color: '#DCDCDC',
					width: 1
				})
			})
		  });
	  }else if(pitch>30 && pitch<=40){
		  style = new ol.style.Style({
			image: new ol.style.Circle({
				radius: 5,//半径
				fill: new ol.style.Fill({//填充样式
					color: colorhash[3],
				}),
				stroke: new ol.style.Stroke({//边界样式
					color: '#DCDCDC',
					width: 1
				})
			})
		  });
	  }else if(pitch>40 && pitch<=50){
		  style = new ol.style.Style({
			image: new ol.style.Circle({
				radius: 5,//半径
				fill: new ol.style.Fill({//填充样式
					color: colorhash[4],
				}),
				stroke: new ol.style.Stroke({//边界样式
					color: '#DCDCDC',
					width: 1
				})
			})
		  });
	  }else if(pitch>50){
		  style = new ol.style.Style({
			image: new ol.style.Circle({
				radius: 5,//半径
				fill: new ol.style.Fill({//填充样式
					color: colorhash[5],
				}),
				stroke: new ol.style.Stroke({//边界样式
					color: '#DCDCDC',
					width: 1
				})
			})
		  });
	  }
	  return [style]
	}

var level2num = function(level) {
	var pitchrange=0;
	switch(level) {
		 case '>=0':
			pitchrange=0;
			break;
		 case '>=10':
			pitchrange=10;
			break;
		 case '>=20':
			pitchrange=20;
			break;
		 case '>=30':
			pitchrange=30;
			break;
		 case '>=40':
			pitchrange=40;
			break;
		 case '>=50':
			pitchrange=50;
			break;
	}
	return pitchrange;
}

var pitchQuery=function(){
	var taxiid=$('#select2 option:selected').val()
	var level=$('#select3 option:selected').val()
	var pitchlevel=level2num(level)
	$.ajax({
		type: "post",
		dataType: "json",
		url: 'http://'+localhost+':8000/web/pitchQuery/',
		data: {taxiid:taxiid,pitchlevel:pitchlevel},
		success: function (json) {
			var geojson=json['geojson']
			console.log(geojson)
			vector.setSource(new ol.source.Vector({
				projection:'EPSG:4326',
				features: new ol.format.GeoJSON().readFeatures(geojson)
				}))
			vector.setStyle(styleFunction)
		}
	});
}
